package com.svm.math;

import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.operator.DFTDescriptor;

import com.svm.bean.Parameter;

public class FourierTransform {

	private Parameter parameter;

	public FourierTransform(Parameter parameter) {
		this.parameter = parameter;
	}

	public double[] fft(RenderedImage image) {

		ParameterBlock pb = new ParameterBlock();
		pb.addSource(image);
		pb.add(DFTDescriptor.SCALING_NONE);
		pb.add(DFTDescriptor.REAL_TO_COMPLEX);

		PlanarImage dft = (PlanarImage) JAI.create("dft", pb, null);

		double[] pixels = dft.getData().getPixels(0, 0,
				parameter.getFeatDimenY(), parameter.getFeatDimenX(),
				(double[]) null);

		return pixels;

	}

}
